package com.sanrenzu.everybodytv.ui.column.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.sanrenzu.everybodytv.R;
import com.sanrenzu.everybodytv.bean.zxb.ColumItemBean;

import java.util.List;

/**
 * Created by My on 2016/9/5.
 */
public class ColumItemGridViewAdapter extends BaseAdapter {
    private List<ColumItemBean> list = null;
    private Context context;
    private LayoutInflater inflater;
    public ColumItemGridViewAdapter(Context context, List<ColumItemBean> list) {
        this.context = context;
        this.list = list;
        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        mViewHolder mHolder = null;
        if(convertView==null){
            convertView = inflater.inflate(R.layout.adapter_columitem,parent,false);
            mHolder = new mViewHolder(convertView);
            convertView.setTag(mHolder);
        }else {
            mHolder = (mViewHolder) convertView.getTag();
        }
        mHolder.adapter_columitem_title.setText(list.get(position).getName());
        Glide.with(context).load(list.get(position).getImage()+"").into(mHolder.adapter_columitem_image);

        return convertView;
    }

    class mViewHolder {
        ImageView adapter_columitem_image;
        TextView adapter_columitem_title;

        public mViewHolder(View convertView) {
            adapter_columitem_image = (ImageView) convertView.findViewById(R.id.adapter_columitem_image);
            adapter_columitem_title = (TextView) convertView.findViewById(R.id.adapter_columitem_title);

        }
    }
}
